package com.ftwj.demo.config.swagger;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class CustomSwagger2Config {
    @Bean
    public Docket createRestApi() {
    	ParameterBuilder builder = new ParameterBuilder();  
        List<Parameter> header = new ArrayList<Parameter>();  
        Parameter token = builder.name("x-access-token")
	        .description("令牌")
	        .modelRef(new ModelRef("string"))
	        .parameterType("header")
	        .required(false)
	        .defaultValue("token")
	        .build();  
        header.add(token);  
        
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //在对应根包下的类，才生成接口文档
                .apis(RequestHandlerSelectors.basePackage("com.ftwj"))
                .paths(PathSelectors.any())
                .build();
    }
 
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("兰州飞天网景信息产业有限公司系统接口API")
                .description("兰州飞天网景信息产业有限公司系统接口API")
                .termsOfServiceUrl("http://127.0.0.1:8000/")
                .contact(new Contact("PROJECT-BASE", "http://www.ftwj.com", "ftwj@gmail.com"))
                .version("1.0")
                .build();
    }
 
}
